@extends('admin.layouts')
@section('style')
    <style>
        html,body{
            height:100%;
        }
    </style>
@endsection
@section('main')

<form class="layui-form luck-pane" id="form1" method="post">
    <div class="luck-content clearfix">
        <div class="layer-box">
            <div class="layui-tab-content layui-form-pane">
                <div class="layui-tab-item layui-show">
                    {{csrf_field()}}
                    @foreach($data as $k=>$v)
                    <input type="hidden" name="conf_id[{{$k}}]" value="{{$v->conf_id}}" class="layui-input">
                    <div class="layui-form-item">
                        <label class="luck-form-label">{{$v->conf_title}}</label>
                        <div class="layui-input-inline">
                            @if($v->field_type=='input')
                                <input type="text" name="conf_content[{{$k}}]" value="{{$v->conf_content}}" class="layui-input">
                            @elseif($v->field_type=='textarea')
                                <textarea name="conf_content[{{$k}}]" class="layui-textarea" style="min-height:300px;">{{$v->conf_content}}</textarea>
                            @endif
                        </div>
                    </div>
                    @endforeach
                </div>
            </div>
        </div>
    </div>
    <div class="luck-footer luck-footer-right luck-footer-padding">
        <div class="luck-block">
            <button class="layui-btn" lay-submit lay-filter="sub">{{trans('config.btn_submit')}}</button>
            <button class="layui-btn layui-btn-primary" type="button" id="close">{{trans('config.btn_close')}}</button>
        </div>
    </div>
</form>

@endsection

@section('script')
<script>
    layui.use(['jquery','myform','layer','upload'],function(){
        var $= layui.jquery;
        var index = parent.layer.getFrameIndex(window.name);
        var form = layui.form();
        var load;
        $('#type>div').click(function(){
            if($(this).prev().val()=='radio'){
                $('#radio-value').show();
            }else{
                $('#radio-value').hide();
            }
        });

        form.verify({
            new_required:function(value){
                if(!/[\S]+/.test(value)){
                    return "{{ trans('config.vali_required') }}";
                }
            }
        });
        $('#close').click(function(){
            parent.layer.close(index);
        });

        form.on('submit(sub)', function(data){
            $.ajax({
                url:"{{url('admin/welcome')}}",
                type:"post",
                data:data.field,
                beforeSend:function(){
                    load=layer.load(1, {
                        shade: [0.1,'#fff']
                    });
                },
                success:function(data){
                    if(data.status==200){
                        layer.msg(data.msg,{icon:1,shift:5});
                        parent.layer.close(index);
                        if(data.url=="reload"){
                            parent.location.reload();
                        }
                    }else{
                        layer.msg(data.msg,{icon: 5,shift:6});
                    }
                },
                complete:function(){
                    layer.close(load);
                },
                error:function(){
                    layer.msg("{{trans('config.connect')}}",{icon: 5,shift:6});
                }
            })
            return false;
        });
    });
</script>
@endsection